#-*- codeing = utf-8 -*-
#@Time : 2020/9/13 13:06
#@Author : 阳某
#@File : 多任务异步1.py
#@Software : PyCharm

import requests
import asyncio
import time
start = time.time()
urls = [
    'http://127.0.0.1:5000/aa',
    'http://127.0.0.1:5000/bb',
    'http://127.0.0.1:5000/cc',
]
async def get_page(url):
    print('正在下载',url)
    # requests.get是基于同步的，必须使用基于异步的网络请求模块进行指定的url的请求发送
    # aiohttp是基于异步网络请求模块
    resp = requests.get(url)
    print('下载完毕',resp.text)
tasks = []
for url in urls:
    c = get_page(url)
    task = asyncio.ensure_future(c)
    tasks.append(task)

loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
end = time.time()
print('总耗时:',end-start)     #还是同步的，，6s